package org.bookie.web.pages;

import org.apache.tapestry.IExternalPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.RedirectException;
import org.bookie.framework.CommonBasePage;
import org.bookie.model.services.UserDAO;

/**
 * Page that activates user by it's activation key
 * 
 * @author zubairov
 *
 */
public abstract class Activation extends CommonBasePage implements
		IExternalPage {

	/**
	 * Called from the external service
	 */
	public void activateExternalPage(Object[] parameters, IRequestCycle cycle) {
		String key = null;
		if (parameters.length > 0) {
			key = (String) parameters[0];
		}
		if (null == key) {
			recordError("activation.key.missing");
			return;
		}
		boolean result = getUserDAO().activate(key);
		if (!result) {
			recordError("activation.key.failure");
			return;
		}
		setMessage(getMessages().getMessage("activation.success.message"));
		throw new RedirectException(getPageService().getLink(false,
				getPageName()).getAbsoluteURL());
	}

	public abstract UserDAO getUserDAO();

}
